// ----------------------------------
// RSDK Project: Sonic 1/Sonic 2
// Script Description: Girder Door Object
// Script Author: Christan Whitehead/Simon Thomley
// Unpacked by Rubberduckycooly's script unpacker
// ----------------------------------

//-------Aliases-------//
private alias 55 : TYPE_GIRDERDOOR

// Function declarations
reserve function GirderDoor_DebugDraw
reserve function GirderDoor_DebugSpawn

// Static Values

// Tables

function GirderDoor_DebugDraw
	DrawSprite(0)
end function


function GirderDoor_DebugSpawn
	CreateTempObject(TypeName[Girder Door], 0, object.xpos, object.ypos)
end function


event ObjectMain
	switch object.state
	case 0
		foreach (GROUP_PLAYERS, currentPlayer, ACTIVE_ENTITIES)
			BoxCollisionTest(C_BOX, object.entityPos, -64, -12, 64, 12, currentPlayer, HITBOX_AUTO, HITBOX_AUTO, HITBOX_AUTO, HITBOX_AUTO)
		next
		break
	case 1
		object.priority = PRIORITY_ACTIVE_BOUNDS
		if object[-1].value0 == 1
			if object.value2 == 0
				object.value2 = 1
				object.state++
			end if
		else
			object.value2 = 0
		end if
		foreach (GROUP_PLAYERS, currentPlayer, ACTIVE_ENTITIES)
			BoxCollisionTest(C_BOX, object.entityPos, -64, -12, 64, 12, currentPlayer, HITBOX_AUTO, HITBOX_AUTO, HITBOX_AUTO, HITBOX_AUTO)
		next
		break
	case 2
		object.xpos += object.xvel
		object.value0++
		if object.value0 == 64
			object.value0 = 0
			object.state++
		end if
		foreach (GROUP_PLAYERS, currentPlayer, ACTIVE_ENTITIES)
			BoxCollisionTest(C_BOX, object.entityPos, -64, -12, 64, 12, currentPlayer, HITBOX_AUTO, HITBOX_AUTO, HITBOX_AUTO, HITBOX_AUTO)
			if checkResult == 1
				object[currentPlayer].xpos += object.xvel
			end if
		next
		break
	case 3
		object.value0++
		if object.value0 == 180
			object.value0 = 0
			object.state++
		end if
		foreach (GROUP_PLAYERS, currentPlayer, ACTIVE_ENTITIES)
			BoxCollisionTest(C_BOX, object.entityPos, -64, -12, 64, 12, currentPlayer, HITBOX_AUTO, HITBOX_AUTO, HITBOX_AUTO, HITBOX_AUTO)
		next
		break
	case 4
		object.xpos -= object.xvel
		object.value0++
		if object.value0 == 64
			object.value0 = 0
			object.state = 1
		end if
		foreach (GROUP_PLAYERS, currentPlayer, ACTIVE_ENTITIES)
			BoxCollisionTest(C_BOX, object.entityPos, -64, -12, 64, 12, currentPlayer, HITBOX_AUTO, HITBOX_AUTO, HITBOX_AUTO, HITBOX_AUTO)
			if checkResult == 1
				object[currentPlayer].xpos -= object.xvel
			end if
		next
		break
	end switch
end event


event ObjectDraw
	DrawSprite(0)
end event


event ObjectStartup
	LoadSpriteSheet("SBZ/Objects.gif")
	SpriteFrame(-64, -12, 128, 24, 383, 140)
	foreach (TypeName[Girder Door], arrayPos0, ALL_ENTITIES)
		switch object[arrayPos0].propertyValue
		case 1
			object[arrayPos0].state = 1
			object[arrayPos0].xvel = 0x20000
			break
		case 2
			object[arrayPos0].state = 1
			object[arrayPos0].xvel = -0x20000
			break
		end switch
		object[arrayPos0].value1 = object[arrayPos0].xpos
	next
	SetTableValue(TypeName[Girder Door], DebugMode_ObjCount, DebugMode_TypesTable)
	SetTableValue(GirderDoor_DebugDraw, DebugMode_ObjCount, DebugMode_DrawTable)
	SetTableValue(GirderDoor_DebugSpawn, DebugMode_ObjCount, DebugMode_SpawnTable)
	DebugMode_ObjCount++
end event

event RSDKDraw
	DrawSprite(0)
end event

event RSDKLoad
	LoadSpriteSheet("Global/Display.gif")
	SpriteFrame(-16, -16, 32, 32, 1, 143)
end event
